package com.gameley.dmgtpf.common.core.cinfig;

import com.gameley.dmgtpf.common.core.listener.MyAppListener;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class MyServiceConfig
{
    @Bean
    public ServletListenerRegistrationBean<com.gameley.dmgtpf.common.core.listener.MyAppListener> regMyListener()
    {
        
        System.err.println("MyServiceConfig...注册...ServletListenerRegistrationBean...");
        
        ServletListenerRegistrationBean<com.gameley.dmgtpf.common.core.listener.MyAppListener> registrationBean =
            new ServletListenerRegistrationBean<com.gameley.dmgtpf.common.core.listener.MyAppListener>(new MyAppListener());
        return registrationBean;
    }
    
    @Bean
    public FilterRegistrationBean<com.gameley.dmgtpf.common.core.filter.MyAppFilter> regMyFilter()
    {
        System.err.println("MyServiceConfig...注册...FilterRegistrationBean...");
        
        FilterRegistrationBean<com.gameley.dmgtpf.common.core.filter.MyAppFilter> registrationBean =
            new FilterRegistrationBean<com.gameley.dmgtpf.common.core.filter.MyAppFilter>();
        registrationBean.setFilter(new com.gameley.dmgtpf.common.core.filter.MyAppFilter());
        // 請求地址
        registrationBean.setUrlPatterns(Arrays.asList("/FoodServlet", "/food"));
        
        return registrationBean;
    }
    
    @Bean
    public ServletRegistrationBean<com.gameley.dmgtpf.common.core.servlet.MyAppServlet> regMyServlet()
    {
        System.err.println("MyServiceConfig...注册...ServletRegistrationBean...");
        
        ServletRegistrationBean<com.gameley.dmgtpf.common.core.servlet.MyAppServlet> servletRegistrationBean =
            new ServletRegistrationBean<com.gameley.dmgtpf.common.core.servlet.MyAppServlet>(new com.gameley.dmgtpf.common.core.servlet.MyAppServlet(),
                "/MyServlet");
        
        return servletRegistrationBean;
    }
    
}
